<template>
	<view class="container">
		<view v-if="list.length>0">
			<uni-list v-for="item in list">
				<uni-list-item :title="item.name" :thumb="path+item.avatarBytes" thumb-size="lg"
					:note="item.type==2? '通行时间:'+item.dateTimeFrom+'--'+item.dateTimeTo:''" rightText="审核" clickable
					@click="onExamine(item.id)">
				</uni-list-item>
			</uni-list>
		</view>

		<view v-else>
			<no-data />
		</view>
		<view>
			<!-- 审核弹框 -->
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose" mode="input" title="审核" v-slot:default>
					<view class="example">
						<uni-forms ref="valiForm" :rules="rules" :modelValue="form" label-width="80px">
							<uni-forms-item label="审核结果" required name="status">
								<uni-data-checkbox v-model="form.status" :localdata="statusList" />
							</uni-forms-item>
							<uni-forms-item label="审核意见" name="remark">
								<uni-easyinput type="textarea" v-model="form.remark" placeholder="请输入审核意见" />
							</uni-forms-item>
						</uni-forms>
						<button type="default" size="mini" @click="close">取消</button>
						<button type="primary" size="mini" @click="submit('valiForm')">提交</button>
					</view>
				</uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import {
		request,
		baseURL
	} from "@/api/request.js"

	import {
		getGroupList,
		getGroupName
	} from "../../utils/common"
	import noData from "../../component/no-data.vue"
	export default {
		data() {
			return {
				list: [],
				path: baseURL + '/api/v1/common/download/',
				form: {
					id: "",
					remark: "",
					status: 2
				},
				statusList: [{
					text: '同意',
					value: 2
				}, {
					text: '驳回',
					value: 1
				}],
				receptionUserId: "",
				groupId:"",
				// 校验规则
				// rules: {
				// 	name: {
				// 		rules: [{
				// 			required: true,
				// 			errorMessage: '姓名不能为空'
				// 		}]
				// 	},
				// 	age: {
				// 		rules: [{
				// 			required: true,
				// 			errorMessage: '年龄不能为空'
				// 		}, {
				// 			format: 'number',
				// 			errorMessage: '年龄只能输入数字'
				// 		}]
				// 	}
				// },
			}
		},
		components: {
			'no-data': noData
		},
		onLoad(options) {
			this.receptionUserId = options.receptionUserId;
			this.groupId=options.groupId
			this.getList(this.groupId,this.receptionUserId)
		},
		methods: {
			onExamine(id) {
				this.form = {
					id,
					remark: "",
					status: 2
				}
				this.$refs.inputDialog.open()
			},
			getList(groupId,receptionUserId) {
				request({
					url: '/api/v1/people-info/guest',
					method: 'POST',
					data: {
						type: 2,
						current: 1,
						size: 100,
						status: 0,
						receptionUserId: receptionUserId,
						groupId,
					}
				}).then(res => {
					this.list = res.data.records;
				})
			},
			submit(ref) {
				this.$refs[ref].validate().then(res => {
					request({
						url: '/api/v1/people-info/examine_app_guest',
						method: 'POST',
						data: this.form
					}).then(res => {
						// if (res.code == 1) {
						// 	uni.redirectTo({
						// 		url: "/pages/examine/index"	
						// 	});
						// }
						this.getList(this.groupId,this.receptionUserId)
						uni.showToast({
							icon: 'none',
							title: res.message
						})

					})
					this.$refs.inputDialog.close()
				}).catch(err => {
					console.log('err', err);
				})
			},
			close() {
				this.$refs.inputDialog.close()
			},
		}
	}
</script>

<style>
	.uni-forms-item__content {
		margin-top: 5px;
	}

	.example {
		width: 90%;
	}

	.uni-popup-dialog .uni-dialog-content {
		padding: 20px 0px;
	}

	button {
		margin-left: 40px;
	}
</style>